import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:safe_manage/config/my_app_provider.dart';

class BaseTabBarController extends GetxController {
  BaseTabBarController();

  /// 响应式成员变量，默认位置指引0
  final currentPage = 0.obs;

  /// PageView页面控制器
  late PageController pageController;

  /// 底部BottomNavigationBarItem
  final bottomTabs = <BottomNavigationBarItem>[].obs;
  switchBottomTabBar(int index) {
    //点击底部BottomNavigationBarItem切换PageView页面
    //pageController.animateToPage(index,duration: Duration(seconds: 1),curve: Curves.fastLinearToSlowEaseIn);
    //pageController.jumpToPage(index);
    currentPage.value = index;
    if (Get.context?.read<MyAppProvider>().tabChange != null) {
      Get.context?.read<MyAppProvider>().tabChange!(index);
    }
  }

  // onPageChanged(int index) {
  //   currentPage.value = index;
  // }
  /// 在Widget内存中分配后立即调用，可以用它来初始化initialize一些东西
  @override
  void onInit() {
    super.onInit();
    pageController = PageController(initialPage: currentPage.value);
  }
}
